function matrixReshape(mat: number[][], r: number, c: number): number[][] {
  let len: number = mat.length * mat[0].length;
  let newArr: Array<number>[] = [];
  let nArr: number[] = [];
  if (r * c != len) {
    return mat;
  }
  nArr = mat.flat();
  for (let i = 0; i < r; i++) {
    newArr.push(nArr.splice(0, c));
  }
  return newArr;
}
console.log(matrixReshape([[1, 2]], 1, 2));
